/**
 * 
 */
package org.gbif.metadata.io;

import java.io.File;

import javax.servlet.ServletContext;

import org.apache.commons.io.FileUtils;

/**
 * File Utilities
 * 
 * @author davemartin
 */
public class MetadataFileUtils {

	/** Directory path for the metadata */
	public static final String metadataDirectoryPath = "/metadata";
	
	/**
	 * Create a new file.
	 * 
	 * @param context
	 * @param docId
	 * @return
	 */
	public static File getNewFile(ServletContext context, String docId) throws Exception{
		String directoryFilePath = context.getRealPath("/");
		File metadataDirectory = new File(directoryFilePath
				+ metadataDirectoryPath);

		if (!metadataDirectory.exists()) {
			// create it
			FileUtils.forceMkdir(metadataDirectory);
		}

		File file = new File(metadataDirectory.getPath()
				+ "/eml-" + docId + ".xml");		
		
		return file;
	}
	
}
